#include <iostream>
#include <string>
#include <vector>

class Rating
{
private:
    std::string title;
    double rating;
    std::string introduction;

public:
    void set_rating(double r)
    {
        rating = r;
    };

    double &get_rating()
    {
        return rating;
    }

    void set_introduction(std::string intro)
    {
        introduction = intro;
    };

    std::string &get_introduction()
    {
        return introduction;
    }

    void set_title(std::string tit)
    {
        title = tit;
    };

    std::string &get_title()
    {
        return title;
    }

    Rating(std::string title, double rating, std::string introduction);
    Rating(const Rating &r);
    Rating operator=(const Rating &r);

    friend std::ostream &operator<<(std::ostream &os, const Rating &r)
    {
        os << "Books information:" << std::endl;
        os << "\tTitle: " << r.title << std::endl;
        os << "\tRating: " << r.rating << std::endl;
        os << "\tIntroduction: " << r.introduction << std::endl;
        return os;
    };

    ~Rating();
};

Rating::Rating(std::string title = "null", double rating = 0, std::string introduction = std::string("null")) : rating(rating), introduction(introduction), title(title)
{
}

Rating::~Rating()
{
}

// 复制构造函数
Rating::Rating(const Rating &r)
{
    title = r.title;
    rating = r.rating;
    introduction = r.introduction;
};

Rating Rating::operator=(const Rating &r)
{
    if (this == &r)
    {
        return *this;
    }
    title = r.title;
    rating = r.rating;
    introduction = r.introduction;
    return *this;
}

// 声明几个函数
bool Set_Goods(Rating &temp);
void Show_Goods(Rating goods);

int main(int argc, char const *argv[])
{
    using std::cin;
    using std::cout;
    using std::endl;
    using std::vector;

    vector<Rating> goods;
    Rating temp;

    while (Set_Goods(temp))
    {
        goods.push_back(temp);
    }
    int goods_num = goods.size();

    if (goods_num > 0)
    {
        cout << "You have input these goods: " << endl;
        // 使用传统for
        // for (int i = 0; i < goods_num; i++)
        // {
        //     Show_Goods(goods[i]);
        // }

        // 使用增强for循环
        // for (auto &v : goods)
        // {
        //     Show_Goods(v);
        // }

        // 使用迭代器进行循环
        // std::vector<Rating>::iterator iter;
        // for (iter = goods.begin(); iter != goods.end(); iter++){
        //     Show_Goods(*iter);
        // }

        // 使用STL非成员函数











    }
    else
    {
        cout << "You have input nothing!!" << endl;
    }
    return 0;
}

bool Set_Goods(Rating &temp)
{
    using namespace std;

    // 这里建立一个临时变量更好,我是用的cin,不能输入空格(将空格之后的内容截断)
    cout << "Enter a good title: (quit to exit)" << endl;
    cin >> temp.get_title();

    if (temp.get_title() == "quit")
    {
        return false;
    }

    cout << "Enter a good rating: " << endl;
    cin >> temp.get_rating();

    cout << "Enter a good introduction: " << endl;
    cin >> temp.get_introduction();

    if (!cin)
    {
        cout << "input error EXITING..." << endl;
        return false;
    }

    while (std::cin.get() != '\n')
    {
        continue;
    }

    return true;
}

void Show_Goods(Rating goods)
{
    using namespace std;
    cout << endl;
    // 这里使用的cout和Rating类的友元函数
    cout << goods << endl;
}